package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Title  string  `gorm:"type:varchar(20);not null;index:ip_idx"`
	Price  float64 `gorm:"type:decimal(10,2);not null;index:ip_idx"`
	Cover  string  `gorm:"type:varchar(20);not null;index:ip_idx"`
	Stock  int     `gorm:"type:int;not null;index:ip_idx"`
	Status string  `gorm:"type:enum('未审核','已审核');not null;index:ip_idx"`
	Type   string  `gorm:"type:varchar(20);not null;index:ip_idx"`
}

func (g *Goods) Create() error {
	return DB.Create(&g).Error
}

func (g *Goods) GoodsStatus(id int, status string) error {
	return DB.Model(Goods{}).Where("id=?", id).Update("status", status).Error
}

func (g *Goods) List(status string) (goods []*Goods) {
	if status == "" {
		DB.Debug().Find(&goods)
	} else {
		DB.Debug().Where("status", status).Find(&goods)
	}
	return
}
